GBML manual / Drawing

draw_rect_anchored

draw_rect, but the position is measured from a spot on the screen (ANCHOR_TOP_CENTER, ANCHOR_CENTER, ...) instead of from the top-left corner, and it is fixed to the screen wherever you call it - a selection frame or a border that stays put on any screen.

Works differently on Game Boy - A rectangle on the Game Boy is made of sprites and drawn in the 4 shades: red, blue and magenta come out dark grey, green, yellow, cyan and white light grey. It shares the 40 sprites on the screen (10 a line); a big box is cut short.

Works differently on Game Boy Color - Rectangles are made of sprites and share the 40 on the screen (10 a line): bars, frames and small boxes are exact, a big box is cut short. Colors come 3 to a free sprite palette, others become the nearest. On the screen they are behind sprites and text.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_rect_anchored(anchor, x, y, w, h, color)

Arguments

NameType
anchoranchor
xreal
yreal
wreal
hreal
colorshape_color

Returns

Nothing.

Description

draw_rect, with the position measured from a named spot on the screen (an anchor) instead of from the top-left corner. It draws a thin outline, never filled - a selection frame, a border, a box pinned to an edge. The anchored call is fixed to the screen wherever you write it (a Step event, a script, any event), not only in a Draw GUI event.

x moves right and y moves down from the anchor. After that come w, h and color, exactly as in draw_rect. (x, y) is the rectangle's top-left corner, measured from the anchor. So a box that should be centered on ANCHOR_CENTER says x = -w / 2 and y = -h / 2.

Example

draw_rect_anchored(ANCHOR_CENTER, -50, -10, 100, 20, COLOR_WHITE);

A white outline 100 pixels wide and 20 tall, in the middle of the screen (its corner is half the width, 50, left of the middle and half the height, 10, above it) - the frame a menu might draw around whichever row is picked.

On the GBA

Exactly draw_rect in a Draw GUI event once the anchor is added to (x, y): up to 4 hardware sprites and up to 2 affine matrices per call (the GBA has 32 matrices in all), always on the front-most layer - see draw_rect's own note for the exact numbers. (x, y) is the rectangle's top-left corner, measured from the anchor. ANCHOR_CENTER is the point (120, 80) on the 240x160 screen, counting from its top-left pixel.

See also: Screen anchorsdraw_rectdraw_rect_fill_anchoredANCHOR_CENTER